<?php

namespace common\exception;

use Yii;
use yii\web\ErrorHandler as BaseErrorHandler;

class ErrorHandler extends BaseErrorHandler
{
    public function renderException($exception)
    {
        if (Yii::$app->request->getIsAjax()) {
            exit(json_encode(array('code' => $exception->getCode(), 'msg' => YII_ENV_PROD ? '404' : $exception->getMessage())));
        } else {
            $errorView = '@douyin/views/site/error.php';
            echo Yii::$app->getView()->renderFile($errorView, ['exception' => $exception, 'message' => $exception->getMessage()], $this);
        }
    }
}